<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;

class IndexContentResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $link_to = $this->link_to;
        if($link_to == null){
            $link_to = config('app.url').'/article/'.$this->id;
        }
        return [
            'id' => $this->id,
            'order' => $this->order,
            'title' => $this->title,
            'picture' => config('app.url').'/uploads/'.$this->picture,
            'subtitle' => $this->subtitle,
            'summary' => str_limit(strip_tags($this->content), 255),
            'link_to' => $link_to
        ];
    }
}
